package auctionhaus

import org.junit.*

/**
 * Created by IntelliJ IDEA.
 * User: Todd
 * Date: 2/5/12
 * Time: 1:07 PM
 * To change this template use File | Settings | File Templates.
 */
class CustomerIntegrationTests extends GroovyTestCase{
    def customerService 

    void testEmailAddressUnique() {
        def alice = new Customer(emailAddress: 'alice@umn.edu', password: 'password')
        assert customerService.createCustomer(alice) == alice
        assert null == alice.errors['emailAddress']
        
        def bob = new Customer(emailAddress: 'bob@umn.edu', password: 'password')
        assert customerService.createCustomer(bob) == bob
        assert null == bob.errors['emailAddress']
        
        def alice2 = new Customer(emailAddress: 'alice@umn.edu', password: 'pw')
        customerService.createCustomer(alice2) == alice2
        assert 'unique' == alice2.errors['emailAddress'].code
    }

    //This is to verify that the dateCreated is automatically set and never null after the Customer is saved
    //since the dateCreated field cannot have a nullable : false constraint
    void testDateCreatedSetOnSave() {
        def alice = new Customer(emailAddress: 'alice@umn.edu', password: 'password')
        assert customerService.createCustomer(alice) == alice
        assert null != alice.dateCreated
    }
}
